package org.caenv.interpreter.pojo.instructions;

import java.util.LinkedList;
import java.util.List;

public class State {

    private final List<Instruction> instructions;
    private final String name;
    private Integer instructionPointer;

    public State(String name) {
        this.name = name;
        this.instructions = new LinkedList<Instruction>();
        this.instructionPointer = 0;
    }

    public boolean addInstruction(Instruction instruction) {
        return this.instructions.add(instruction);
    }

    public Instruction[] getInstructions() {
        return this.instructions.toArray(new Instruction[this.instructions.size()]);
    }

    public String getName() {
        return name;
    }

    public void initializeState() {
        this.instructionPointer = 0;
    }

    public Instruction nextInstruction() {
        if (this.instructionPointer < this.instructions.size()) {
            return this.instructions.get(this.instructionPointer++);
        } else {
            return null;
        }
    }

    public void setInstructionPointer(Integer instructionPointer) {
        this.instructionPointer = instructionPointer;
    }

}
